/*
 * AnimalMoving.hpp
 *
 *  Created on: 2013-1-18
 *      Author: heqiu
 */

#ifndef ANIMALMOVING_HPP_
#define ANIMALMOVING_HPP_

#include "AnimalUnit.hpp"
#include "AnimalPosition.hpp"

class AnimalMoving {
public:
	AnimalMoving() {
		m_pAnimalPosition = NULL;
	}
	void init(AnimalPosition * pAnimalPosition) {
		m_pAnimalPosition = pAnimalPosition;
	}
	void addAnimal(AnimalUnit & stAnimalUnit) {
		if (m_mapPAnimal.find(stAnimalUnit.m_iId) == m_mapPAnimal.end()) {
			m_mapPAnimal[stAnimalUnit.m_iId] = &stAnimalUnit;
		}
	}
	void delAnimal(uint32_t uiId) {
		m_mapPAnimal.erase(uiId);
	}
	void moving() {
		uint32_t uiTime = SDL_GetTicks();
		for (map<uint32_t, AnimalUnit *>::iterator it = m_mapPAnimal.begin();
				it != m_mapPAnimal.end(); it++) {
			int iX;
			int iY;
			it->second->moving(uiTime, iX, iY);
			if (m_pAnimalPosition != NULL) {
				m_pAnimalPosition->addAnimal(it->first, iX, iY);
			}
		}
	}
private:
	map<uint32_t, AnimalUnit *> m_mapPAnimal;
	AnimalPosition * m_pAnimalPosition;
};

#endif /* ANIMALMOVING_HPP_ */
